﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DeliveryBatchDevice.aspx.cs" Inherits="H2.NET.Web.Pages.SMD.DeliveryBatchDevice" %>
<%@ Register Src="../../Controls/DwzAssessment.ascx" TagName="DwzAssessment" TagPrefix="uc" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
<head runat="server">
    <title>发机批量确认</title>
    <link href="../../Resource/Css/Style.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/jBox/Blue/jbox.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/LigerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/LigerUI/skins/Gray2014/css/all.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/LigerUI/LigeruiExtend.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/JqueryUI/css/smoothness/jquery-ui-1.10.4.custom.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/qtip/jquery.qtip.min.css" rel="stylesheet" type="text/css" />
    <link href="../../Resource/Css/Pager.css" rel="stylesheet" type="text/css" />
    <script src="../../Resource/dwz/js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../Resource/Js/Common.js" type="text/javascript"></script>
    <script src="../../Resource/jBox/jquery.jBox-2.3.min.js" type="text/javascript"></script>
    <script src="../../Resource/jBox/jquery.jBox-zh-CN.js" type="text/javascript"></script>
    <script src="../../Resource/LigerUI/js/ligerui.all.js" type="text/javascript"></script>
    <script src="../../Resource/JqueryUI/js/jquery-ui-1.10.4.custom.min.js" type="text/javascript"></script>
    <script src="../../Resource/qtip/jquery.qtip.min.js" type="text/javascript"></script>
        <script src="../../Resource/Js/jquery.pager.js" type="text/javascript"></script>
    <style type="text/css">
        #ass_table th { width:15%; }
        #ass_table td { width:85%; }
        .formTable input.txt { width:94%; height:100%; }
    </style>
    <script type="text/javascript">
        /* 打开选择门店窗体 st */
        var currentInput;
        function openStoreDialog(obj) {
            setTimeout(function () {
                MphSearch(1);
            }, 100);

            currentInput = obj;
            if ($(obj).hasClass("search")) {
                $.jBox("id:uc_search_mp_td", {
                    title: "双击选择美萍号",
                    width: 300,
                    height: 500,
                    buttons: {}
                });
            }
        }

        /* 打开选择设备窗体 st */
        function openDeviceDialog(obj, storeid) {
            currentInput = obj;
            $("#storeId").val(storeid);
            $("#incident").val($(obj).attr("incident"));
            if ($(obj).hasClass("search")) {
                $.jBox("id:search_deviceno", {
                    title: "双击选择设备",
                    width: 1000,
                    height: 500,
                    buttons: {}
                });
            }
        }

        /* 打开选择门店窗体 ed */
        function search(arg) {
            $.ajax({
                type: 'POST',
                url: '<%=Page.ResolveUrl("~/pages/smd/ajaxtools/handler.ashx")%>',
                data: { action: 'search_mp', keywords: $.jBox.getBox().find(":text[name='tb_keywords']").val() },
                beforeSend: function () {
                    $.jBox.getBox().find("#btn_search").val("加载中...");
                },
                complete: function () {
                    $.jBox.getBox().find("#btn_search").val("检索");
                },
                success: function (result) {
                    $.jBox.getBox().find("#dialog_tbody").html(result);
                    var same = false;
                    $.jBox.getBox().find("#dialog_tbody tr").dblclick(function () {
                        var value = $(this).find("[name=SerialNumber]").html();

                        $("[name ^= 'MeiPinNo']").each(
                        function () {
                            if ($(this).val() == value) {
                                alert("不能选相同的美萍号");
                                same = true;
                            }
                        });
                        if (!same) {
                            $(currentInput).val(value);
                        }
                        $.jBox.getBox().remove();
                    });
                }
            });
        }


        var MphSearch = function searchMPH(pageclickednumber) {
            $.ajax({
                type: 'POST',
                url: '<%=Page.ResolveUrl("~/pages/smd/ajaxtools/handler.ashx")%>',
                data: { action: 'search_mp',
                    keywords: $.jBox.getBox().find(":text[name='mphName']").val(),
                    pageNumber: pageclickednumber,
                    pageSize: 14
                },
                beforeSend: function () {
                    $.jBox.getBox().find("#btn_mph_search").val("加载中...");
                },
                complete: function () {
                    $.jBox.getBox().find("#btn_mph_search").val("检索");
                },
                success: function (result) {
                    $("#jbox-content #pager").pager({ pagenumber: pageclickednumber, pagecount: result.pageNum, buttonClickCallback: MphSearch });
                    var data = result.data;
                    var html = "";
                    for (var o in data) {
                        html += "<tr mph='" + data[o].SerialNumber + "'>";
                        html += " <td align=center>" + data[o].SerialNumber + "</td>";
                        html += "</tr>";
                    }

                    $.jBox.getBox().find("#dialog_mph_tbody").html(html);

                    var same = false;

                    $.jBox.getBox().find("#dialog_mph_tbody tr").dblclick(function () {
                        var value = $(this).attr("mph");
                        $("[name ^= 'MeiPinNo']").each(
                        function () {
                            if ($(this).val() == value) {
                                alert("不能选相同的美萍号");
                                same = true;
                            }
                        });
                        if (!same) {
                            $(currentInput).val(value);
                        }
                        $.jBox.getBox().remove();
                    });
                }
            });
        }




        function searchDevice() {
            var sid = $("#storeId").val()
            $.ajax({
                type: 'POST',
                url: '<%=Page.ResolveUrl("~/pages/smd/ReceiveDeposit.aspx")%>',
                data: { action: 'chooseDevice', storeid: sid, keywords: $.jBox.getBox().find(":text[name='deviceName']").val() },
                beforeSend: function () {
                    $.jBox.getBox().find("#btn_device_search").val("加载中...");
                },
                complete: function () {
                    $.jBox.getBox().find("#btn_device_search").val("检索");
                },
                success: function (result) {
                    result = $.parseJSON(result);
                    var html = "";
                    var rst = result.navTabId.split("|");
                    for (var i = 0; i < rst.length; i++) {
                        if (rst[i]) {
                            var list = rst[i].split(",");
                            var html = "";
                            if (list.length > 0) {
                                var deviceAll = list[1] + "|" + list[4] + "|" + list[7];
                                html += "<tr deviceId='" + list[0] + "' deviceALL='" + deviceAll + "'>";
                                for (var j = 1; j < list.length; j++) {
                                    html += "<td style='text-align:center'>" + list[j] + "</td>";
                                }
                                html += "</tr>";
                                $.jBox.getBox().find("#dialog_device_tbody").html(html);
                            }
                        }
                    }

                    $.jBox.getBox().find("#dialog_device_tbody tr").dblclick(function () {
                        
                        var ic = $("#incident").val()
                        var did = "" + "#DeviceId" + ic + "";
                        var value = $(this).attr("deviceId")
                        var same = false;
                        $("[name ^= 'DeviceId']").each(function () {
                            if ($(this).val() == value) {
                                alert("不能选同一个设备！");
                                same = true;
                            }
                        });
                        if (!same) {
                            $("" + did + "").val(value);
                            $(currentInput).val($(this).attr("deviceall"));
                        }
                        $.jBox.close();
                    });
                }
            });
        }
    </script>
</head>
<body>
    <form runat="server">
        <div class="flowpage">
            <!-- 标题 st -->
            <div class="ffh">
                <table style="width: 100%;">
                    <tr>
                        <td class="logo">
                            <img alt="" src="../../Resource/Images/Logo_AkzoNobel.gif" />
                        </td>
                        <td class="title">
                            <b><%=TaskAPI.Summary.Split('|')[0]%></b>
                        </td>
                        <td class="info" align="left">
                            <div>
                                <label>&nbsp;</label>
                            </div>
                            <div>
                                <label>Date：</label>
                                <%=DateTime.Now.ToString("yyyy-MM-dd")%>
                            </div>
                            <div>
                                <label>Applicator：</label>
                                <%=UserAPI.UserFullName%>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <!-- 标题 ed -->

            <div class="flowContent">
                <table class="formTable">
                    <thead>
                        <tr>
                            <th style="text-align:center;width:5%">序号</th>
                            <th style="text-align:center;width:8%">授权号</th>
                            <th style="text-align:center;width:10%">门店名称</th>
                            <th style="text-align:center;width:10%">固定资产号</th>
                            <th style="text-align:center;width:12%">美萍号</th>
                            <th style="text-align:center;width:12%">设备号</th>
                            <th style="text-align:center;width:5%">发放方式</th>
                            <th style="text-align:center;width:20%">发放地址</th>
                        </tr>
                    </thead>        
                    <tbody>
                        <%
                            int i = 1;
                            foreach(var dt in data){
                        %>
                            <tr>
                                <td style="text-align:center"><%:dt.Incident %>
                                    <input type="hidden" name="Incident" value="<%= dt.Incident %>" />
                                </td>
                                <td><%:dt.AuthID %></td>
                                <td><%:dt.StoreName %></td>
                                <td><input type='text' name='FullSetSN<%=dt.Incident %>' class="txt"/></td>
                                <td><input type='text' name='MeiPinNo<%=dt.Incident %>' class="txt search required" onclick="openStoreDialog(this)" readonly="readonly"/></td>
                                <td>
                                    <input type='text' name='DeviceAll<%=dt.Incident %>'class="txt search required" incident='<%=dt.Incident %>' onclick="openDeviceDialog(this,'<%=dt.StoreId%>')" readonly="readonly"/>
                                    <input type='hidden' name='DeviceId<%=dt.Incident %>' id="DeviceId<%=dt.Incident %>"/>
                                </td>
                                <td><select name="DeliveryType<%=dt.Incident %>">
                                    <option value="">请选择</option>
                                    <%foreach (System.Data.DataRow row in deliveryType.Rows)
                                      {%>
                                      <option value="<%=row["value"].ToString()%>" <%=dt.NewFitment == row["name"].ToString()?"selected":"" %>><%=row["name"].ToString()%></option>
                                    <%} %>
                                </select></td>
                                <td colspan="5"><input type='text' name="Address<%=dt.Incident %>" style="width:80%" value="<%=dt.Location %>" /></td>
                            </tr>
                        <%
                                i++;
                            }    
                         %>
                    </tbody>
                </table>
                <input type="hidden" id="storeId" />
                <input type="hidden" id="incident" />
                 <div class="flowContent">
                    <div id="storegrid" style="margin-bottom:5px;"></div>
                    <table id="ass_table" class="formTable" style="margin-top: 10px;">
                        <tbody>
                            <uc:DwzAssessment ID="DwzAssessment1" runat="server" />
                        </tbody>
                    </table>
                    <div class="flowBtns">
                        <asp:Button ID="Button1" runat="server" CssClass="u-btn" Text="提交(Submit)" OnClientClick="return confirmSubmit();" OnClick="Button1_Click" />
                        <input type="button" class="u-btn u-btn-c4" value="关闭(Close)" onclick="custom_close()" />
                    </div>
                </div>
            </div>
        </div>
    </form>
    <div id="uc_search_mp_td" style="display:none;">
        <div class="dialog_content" style="98%">
            <div class="dialog_head_search">
                <input type="text" name="tb_keywords" placeholder="请输入序列号" size="35" />
                <input type="button" id="btn_search" value="检索" onclick="MphSearch(1)" />
            </div>  
            <table class="htable">
                <thead>
                    <tr>
                        <th style="text-align:center;width:80%">美萍号</th>
                    </tr>
                </thead>
               <tbody id="dialog_mph_tbody">
                    <tr>
                        <td colspan="3" style="text-align: center;">
                            请输入关键字检索
                        </td>
                    </tr>
                </tbody>
            </table>
            <div id="pager"></div>
        </div>
    </div>

    <!-- 选择设备号 st -->
    <div colspan="5" id="search_deviceno" style="display: none">
        <div class="dialog_content" style="width:98%">
            <div class="dialog_head_search">
                <input type="text" name="deviceName" placeholder="请输入设备号" size="40" />
                <input type="button" id="btn_device_search" value="检索" onclick="searchDevice()" />
            </div>
            <table class="htable">
                <thead>
                    <tr>
                        <th>
                            调色机型号
                        </th>
                        <th>
                            调色机固定资产号
                        </th>
                        <th>
                            调色机序列号
                        </th>
                        <th>
                            震荡机型号
                        </th>
                        <th>
                            震荡机固定资产号
                        </th>
                        <th>
                            震荡机序列号
                        </th>
                        <th>
                            电脑型号
                        </th>
                        <th>
                            电脑固定资产号
                        </th>
                        <th>
                            调色机序列号
                        </th>
                    </tr>
                </thead>
                <tbody id="dialog_device_tbody">
                    <tr>
                        <td colspan="9" style="text-align: center;">
                            请输入关键字检索
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <!-- 选择设备号 ed -->
</body>
</html>
